//
//  HJAboutController.m
//  KaiChat
//
//  Created by lx on 2023/10/18.
//

#import "HJAboutController.h"
#import "HJTitleCell.h"
#import "HJWebViewController.h"
#import "HJVersionUpdate.h"
#import "HJMinePresent.h"

@interface HJAboutController ()

@property (nonatomic, strong) NSArray *datas;

@end

@implementation HJAboutController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.title = @"About Kai";
    
    [self.tableView registerClass:HJTitleCell.class forCellReuseIdentifier:@"HJTitleCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 50;
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(KNavBarHight);
        make.bottom.offset(0);
    }];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 180)];
    
    UIImageView *logoImageView = [UIImageView addToView:headerView];
    logoImageView.addCornerRadius(10);
    logoImageView.image = [UIImage imageNamed:@"about_logo"];
    [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(76);
        make.centerX.inset(0);
        make.top.offset(30);
    }];
    
    UILabel *appNameLabel = [UILabel lableWithSuperView:headerView font:UIFontSemiboldMake(24) color:UIColor.tj_333333Color title:getAppName() textAlignment:NSTextAlignmentLeft];
    [appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(logoImageView.mas_bottom).offset(12);
        make.centerX.offset(0);
    }];
    
    
    self.tableView.tableHeaderView = headerView;
    [self loadData];
}
 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   HJTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HJTitleCell" forIndexPath:indexPath];
   HJCellModel *model = self.datas[indexPath.row];
   cell.model = model;
   return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HJCellModel *model = self.datas[indexPath.row];
    if ([model.identifier isEqualToString:@"service"]) {
        HJWebViewController *webViewController = [[HJWebViewController alloc] init];
        webViewController.type = HJWebViewTypeService;
        webViewController.title = model.text;
        [self.navigationController pushViewController:webViewController];
        return;
    }
    
    if ([model.identifier isEqualToString:@"fresh"]) {
        [self.navigationController pushViewControllerWithName:@"HJVersionListController"];
        return;
    }
    
    if ([model.identifier isEqualToString:@"update"]) {
        [HJVersionUpdate checkVersionUpdateInController:[HJTools currentViewController]];
        return;
    }
}

- (void)loadData {
    [HJMinePresent getAgreementComplete:nil];

}

- (NSArray *)datas {
    if (!_datas) {
        _datas = @[
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.identifier = @"service";
                model.text = @"Terms of Service";
                model.showLine = NO;
            }],
            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
                model.text = @"Kai Fresh";
                model.identifier = @"fresh";
                model.showLine = NO;
            }],
//            [HJCellModel modelWithBlock:^(HJCellModel * _Nonnull model) {
//                model.text = @"Kai Update";
//                model.identifier = @"update";
//                model.showLine = NO;
//            }],
        ];
        
        
    }
    return _datas;
}


@end
